/*
* pps_bom
*/
package com.pitop.mould.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.mould.entity.MouldMaterial;
import com.pitop.mould.service.MouldMaterialSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物料模具关联 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/mouldMaterial")
@Slf4j
@Api(value = "物料模具关联控制器", description = "物料模具关联控制器")
public class MouldMaterialCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MouldMaterialSV mouldMaterialSV;

    /**
     * 查询MouldMaterial一个详情信息
     *
     * @param id
     * @param materialCode 物料编码
     * @param mouldCode    模具编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public MouldMaterial load(Long id, String materialCode, String mouldCode) {
        if (id == null) {
            return null;
        }
        if (materialCode == null) {
            return null;
        }
        if (mouldCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.load(id, materialCode, mouldCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 查询MouldMaterial一个详情信息，(将查询关联数据)
     *
     * @param id
     * @param materialCode 物料编码
     * @param mouldCode    模具编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/get")
    @ResponseBody
    public MouldMaterial get(Long id, String materialCode, String mouldCode) {
        if (id == null) {
            return null;
        }
        if (materialCode == null) {
            return null;
        }
        if (mouldCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.get(id, materialCode, mouldCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件id查询MouldMaterial一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public MouldMaterial loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.loadById(id);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件materialCode查询MouldMaterial一个详情信息
     *
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/materialCode/{materialCode}")
    @ResponseBody
    public MouldMaterial loadByMaterialCode(@PathVariable String materialCode) {
        if (materialCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.loadByMaterialCode(materialCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件mouldCode查询MouldMaterial一个详情信息
     *
     * @param mouldCode 模具编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/mouldCode/{mouldCode}")
    @ResponseBody
    public MouldMaterial loadByMouldCode(@PathVariable String mouldCode) {
        if (mouldCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.loadByMouldCode(mouldCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件id查询MouldMaterial一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/get/id/{id}")
    @ResponseBody
    public MouldMaterial getById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.getById(id);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件materialCode查询MouldMaterial一个详情信息
     *
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/materialCode/{materialCode}")
    @ResponseBody
    public MouldMaterial getByMaterialCode(@PathVariable String materialCode) {
        if (materialCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.getByMaterialCode(materialCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 根据条件mouldCode查询MouldMaterial一个详情信息
     *
     * @param mouldCode 模具编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MouldMaterial一个详情信息", notes = "查询MouldMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/mouldCode/{mouldCode}")
    @ResponseBody
    public MouldMaterial getByMouldCode(@PathVariable String mouldCode) {
        if (mouldCode == null) {
            return null;
        }
        MouldMaterial mouldMaterial = mouldMaterialSV.getByMouldCode(mouldCode);
        log.info(JSON.toJSONString(mouldMaterial));
        return mouldMaterial;
    }

    /**
     * 查询MouldMaterial信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MouldMaterial信息集合", notes = "查询MouldMaterial信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<MouldMaterial> list(@RequestBody @ApiIgnore MouldMaterial mouldMaterial, Integer curPage, Integer pageSize) {
        Page<MouldMaterial> page = new Page<MouldMaterial>(pageSize, curPage);
        List<MouldMaterial> mouldMaterials = mouldMaterialSV.list(mouldMaterial, page.genRowStart(), page.getPageSize());
        int total = mouldMaterialSV.count(mouldMaterial);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return mouldMaterials;
    }

    /**
     * 查询MouldMaterial信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MouldMaterial信息集合", notes = "查询MouldMaterial信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<MouldMaterial> listByPk(Long id, String materialCode, String mouldCode, Integer curPage, Integer pageSize) {
        Page<MouldMaterial> page = new Page<MouldMaterial>(pageSize, curPage);
        List<MouldMaterial> mouldMaterials = mouldMaterialSV.list(id, materialCode, mouldCode, page.genRowStart(), page.getPageSize());
        int total = mouldMaterialSV.count(id, materialCode, mouldCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return mouldMaterials;
    }

    /**
     * 统计MouldMaterial信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计MouldMaterial信息数量根据主键", notes = " 统计MouldMaterial信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String materialCode, String mouldCode) {
        return mouldMaterialSV.count(id, materialCode, mouldCode);
    }

    /**
     * 统计MouldMaterial信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计MouldMaterial信息数量", notes = "统计MouldMaterial信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody MouldMaterial mouldMaterial) {
        return mouldMaterialSV.count(mouldMaterial);
    }

    /**
     * 创建MouldMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建MouldMaterial", notes = "创建MouldMaterial")
    @ApiImplicitParams({
    })
    @PostMapping("/build")
    @ResponseBody
    public MouldMaterial build(@RequestBody @ApiIgnore MouldMaterial mouldMaterial) {
        mouldMaterialSV.save(mouldMaterial);
        return mouldMaterial;
    }

    /**
     * 修改MouldMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改MouldMaterial", notes = "修改MouldMaterial")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public MouldMaterial modify(@RequestBody @ApiIgnore MouldMaterial mouldMaterial) {
        mouldMaterialSV.modify(mouldMaterial);
        return mouldMaterial;
    }

    /**
     * 删除MouldMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除MouldMaterial", notes = "删除MouldMaterial")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "mouldCode", value = "模具编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String materialCode, String mouldCode) {
        mouldMaterialSV.delete(id, materialCode, mouldCode);
        return BeanRet.create(true, "删除MouldMaterial成功");
    }

}
